<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="initial-scale=1, user-scalable=0, minimal-ui">
    <title>投票</title>
    <link rel="stylesheet" href="../view/css/style.min.css">
    <script type="text/javascript" src="../common/js/jweixin-1.0.0.js"></script>
    <script type="text/javascript" src="../common/js/utils.js"></script>
    <script type="text/javascript" src="../config/config.js"></script>

    <style type="text/css">
        html, body {
            height: 100%;
            overflow: hidden;
        }

        body {
            margin: 0;
            padding: 0;
            list-style: none;
        }
    </style>
</head>
<body>


<div>
    <fieldset>
        <div style="height: 100px;">

            <div class="form-row form-row-2" style="float: left;clear: none">
                <h2>投票</h2>

            </div>
        </div>
        <div id="partySign" style="position:relative;">
            <div class="error_dialog">
                <img src="../view/images/error.png">
                <p></p>
            </div>

            <div class="form-row">
                <div class="field-label" style="width: 188px;"><label for="field6"
                                                                      style="width: 160px;">节目清单</label>
                </div>
                <div class="field-widget">
                    <select id="field6" name="dept" class="validate-selection" style="font-size: 16px">
                        <option value="1">节目1</option>
                        <option value="2">节目2</option>
                        <option value="3">节目3</option>
                        <option value="4">节目4</option>
                        <option value="5">节目5</option>
                        <option value="6">节目6</option>
                        <option value="7">节目7</option>
                        <option value="8">节目8</option>
                        <option value="9">节目9</option>
                    </select>
                </div>
            </div>
            <div class="form-row form-row-3" style="">
                <input type="button" class="submit" id="btnSign" value="投票"/>
            </div>
        </div>

    </fieldset>
</div>
</body>

<script type="text/javascript">
    function init() {
        const wxUrl = location.href.split('#')[0];
        const url = BaseUrl + "sign/url?url=" + wxUrl;
        request(url)
            .then(res => {
                const data = res.data;
                const config = {};
                for (let k in data) {
                    config[k] = data[k];
                }
                config.debug = false;// 添加你需要的JSSDK的权限
                config.appId = config.appid;
                config.jsApiList = ['hideOptionMenu'];
                config.timestamp = Number.parseInt(config.timestamp);
                config.nonceStr = config.noncestr;
                config.signature = config.signature
                wx.config(config);

                wx.ready(function () {
                    wx.hideOptionMenu();

                })
            })
    }

    document.getElementById('btnSign').addEventListener('click',function () {
        const vote = BaseUrl + "vote";
        const weixin = location.href.split('?')[1];
        const id = weixin.split('=')[1];

        const mySelect=document.getElementById("field6")

        const index=mySelect.selectedIndex

        const valueSelect = mySelect.options[index].value


        const openId = { id,jid:valueSelect};

        request(vote,openId,'POST','application/json')
            .then(res => {
                alert('投票成功！！！')
            })

    })
    init()

</script>
</html>